<?php

namespace common;

class JsonBuilder
{
    public static function success($data=[],$msg='操作成功',$code='0')
    {
        if (empty($data)){
            $mData = array("code"=>$code,"msg"=>$msg);
        }else{
            $mData = array("code"=>$code,"data"=>$data,"msg"=>$msg);
        }
        return json_encode($mData);
    }
    public static function error($code='1',$msg='操作失败',$data=[])
    {
        if (empty($data)){
            $mData = array("code"=>$code,"msg"=>$msg);
        }else{
            $mData = array("code"=>$code,"data"=>$data,"msg"=>$msg);
        }
        return json_encode($mData);
    }

    const code_0 = 0;//成功  1..100失败
    const code_1 = 1;//失败
    const code_account_success = "注册成功";
    const code_account_error = "注册失败";
    const code_account_has = "该用户已被注册";
}